import { goTo } from '@/modules/move'
import { PCTask, PCTaskType } from '../types'

/**
 * 使用 pc 技能
 */
export const usePower = (pc: PowerCreep, task: PCTask, target?: RoomObject) => {
    if (target) {
        if (pc.pos.getRangeTo(target) > 3) {
            goTo(pc, target.pos)
            return
        }
    }

    if (pc.powers[task.type].cooldown || target?.effects?.find((e) => e.effect === task.type)) return

    pc.usePower(task.type, target)
    task.done = true
}
